# 练习：班级分组⼩程序
# 你们班有55⼈，每个⼈的姓名&考试成绩存在⼀个⼤列表⾥
stu_list = [['李渊', 82], ['李世民', 7], ['侯君集', 5], ['李靖', 58], ['魏征', 41], ['房玄龄', 64], ['杜如晦', 65],
            ['柴绍', 94], ['程知节', 45], ['尉迟恭', 94], ['秦琼', 54], ['长孙无忌', 85], ['李存恭', 98], ['封德彝', 16],
            ['段志玄', 44], ['刘弘基', 18], ['徐世绩', 86], ['李治', 19], ['武则天', 39], ['太平公主', 57], ['韦后', 76],
            ['李隆基', 95], ['杨玉环', 33], ['王勃', 49], ['陈子昂', 91], ['卢照邻', 70], ['杨炯', 81], ['王之涣', 82],
            ['安禄山', 18], ['史思明', 9], ['张巡', 15], ['雷万春', 72], ['李白', 61], ['高力士', 58], ['杜甫', 27],
            ['白居易', 5], ['王维', 14], ['孟浩然', 32], ['杜牧', 95], ['李商隐', 34], ['郭子仪', 53], ['张易之', 39],
            ['张昌宗', 61], ['来俊臣', 8], ['杨国忠', 84], ['李林甫', 95], ['高适', 100], ['王昌龄', 40], ['孙思邈', 46],
            ['玄奘', 84], ['鉴真', 90], ['高骈', 85], ['狄仁杰', 62], ['黄巢', 79], ['王仙芝', 16], ['文成公主', 13],
            ['松赞干布', 47], ['薛涛', 79], ['鱼玄机', 16], ['贺知章', 20], ['李泌', 17], ['韩愈', 100], ['柳宗元', 88],
            ['上官婉儿 五代十国：朱温', 55], ['刘仁恭', 6], ['丁会', 26], ['李克用', 39], ['李存勖', 11], ['葛从周', 25],
            ['王建', 13], ['刘知远', 95], ['石敬瑭', 63], ['郭威', 28], ['柴荣', 50], ['孟昶', 17], ['荆浩', 84],
            ['刘彟', 18], ['张及之', 45], ['杜宇', 73], ['高季兴', 39], ['喻皓', 50], ['历真', 70], ['李茂贞', 6],
            ['朱友珪', 7], ['朱友贞', 11], ['刘守光', 2]]

# 需求：
# 现要求按考试成绩⾼低将学员们分成5组，全存在⼀个新的⼤列表⾥, 5组分别是90-100, 80-89, 70-79, 60-69, 0-59
# 定义分数范围和空列表，用于存储每个分数范围内的学生
group_ranges = {
    "90-100": [],
    "80-89": [],
    "70-79": [],
    "60-69": [],
    "0-59": []
}

# 遍历学生列表，将每个学生按成绩分入对应组别
for student in stu_list:
    name, score = student
    if 90 <= score <= 100:
        group_ranges["90-100"].append(student)
    elif 80 <= score <= 89:
        group_ranges["80-89"].append(student)
    elif 70 <= score <= 79:
        group_ranges["70-79"].append(student)
    elif 60 <= score <= 69:
        group_ranges["60-69"].append(student)
    else:
        group_ranges["0-59"].append(student)

# 将结果存入新的大列表
grouped_students = [group_ranges['90-100'], group_ranges['80-89'], group_ranges['70-79'], group_ranges['60-69'],
                    group_ranges['0-59']]
# 直接打印列表
print(grouped_students)

# 输出结果
for i, group in enumerate(grouped_students):
    print(f"组{i+1} ({list(group_ranges.keys())[i]}):")
    for student in group:
        print(f"  {student[0]}, {student[1]}分")
    print()  # 换行以便分隔每组


